home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 2YQ3IM (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.9 KB  |  131 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.plaf.ToolBarUI;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.beans.PropertyChangeListener;
  11.  
  12. public class JToolBar extends JComponent implements Accessible {
  13.    private boolean paintBorder = true;
  14.    private Insets margin = null;
  15.    private boolean floatable = true;
  16.  
  17.    public JToolBar() {
  18.       ((Container)this).setLayout(new BoxLayout(this, 0));
  19.       this.updateUI();
  20.    }
  21.  
  22.    public JButton add(Action a) {
  23.       JButton b = new JButton((String)a.getValue("Name"), (Icon)a.getValue("SmallIcon"));
  24.       ((AbstractButton)b).setHorizontalTextPosition(0);
  25.       ((AbstractButton)b).setVerticalTextPosition(3);
  26.       ((AbstractButton)b).setEnabled(a.isEnabled());
  27.       ((AbstractButton)b).addActionListener(a);
  28.       ((Container)this).add(b);
  29.       PropertyChangeListener actionPropertyChangeListener = this.createActionChangeListener(b);
  30.       a.addPropertyChangeListener(actionPropertyChangeListener);
  31.       return b;
  32.    }
  33.  
  34.    public void addSeparator() {
  35.       Separator s = new Separator(this);
  36.       ((Container)this).add(s);
  37.    }
  38.  
  39.    protected PropertyChangeListener createActionChangeListener(JButton b) {
  40.       return new ActionChangedListener(this, b);
  41.    }
  42.  
  43.    public AccessibleContext getAccessibleContext() {
  44.       if (super.accessibleContext == null) {
  45.          super.accessibleContext = new AccessibleJToolBar(this);
  46.       }
  47.  
  48.       return super.accessibleContext;
  49.    }
  50.  
  51.    public Component getComponentAtIndex(int i) {
  52.       int ncomponents = ((Container)this).getComponentCount();
  53.       if (i <= ncomponents) {
  54.          Component[] component = ((Container)this).getComponents();
  55.          return component[i];
  56.       } else {
  57.          return null;
  58.       }
  59.    }
  60.  
  61.    public int getComponentIndex(Component c) {
  62.       int ncomponents = ((Container)this).getComponentCount();
  63.       Component[] component = ((Container)this).getComponents();
  64.  
  65.       for(int i = 0; i < ncomponents; ++i) {
  66.          Component comp = component[i];
  67.          if (comp == c) {
  68.             return i;
  69.          }
  70.       }
  71.  
  72.       return -1;
  73.    }
  74.  
  75.    public Insets getMargin() {
  76.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  77.    }
  78.  
  79.    public ToolBarUI getUI() {
  80.       return (ToolBarUI)super.ui;
  81.    }
  82.  
  83.    public String getUIClassID() {
  84.       return "ToolBarUI";
  85.    }
  86.  
  87.    public boolean isBorderPainted() {
  88.       return this.paintBorder;
  89.    }
  90.  
  91.    public boolean isFloatable() {
  92.       return this.floatable;
  93.    }
  94.  
  95.    protected void paintBorder(Graphics g) {
  96.       if (this.isBorderPainted()) {
  97.          super.paintBorder(g);
  98.       }
  99.  
  100.    }
  101.  
  102.    public void setBorderPainted(boolean b) {
  103.       this.paintBorder = b;
  104.       ((Container)this).invalidate();
  105.    }
  106.  
  107.    public void setFloatable(boolean b) {
  108.       if (this.floatable != b) {
  109.          this.floatable = b;
  110.          ((JComponent)this).firePropertyChange("floatable", !this.floatable, this.floatable);
  111.       }
  112.  
  113.    }
  114.  
  115.    public void setMargin(Insets m) {
  116.       Insets old = this.margin;
  117.       this.margin = m;
  118.       ((JComponent)this).firePropertyChange("margin", old, m);
  119.       ((Container)this).invalidate();
  120.    }
  121.  
  122.    public void setUI(ToolBarUI ui) {
  123.       super.setUI(ui);
  124.    }
  125.  
  126.    public void updateUI() {
  127.       this.setUI((ToolBarUI)UIManager.getUI(this));
  128.       ((Container)this).invalidate();
  129.    }
  130. }
  131.